package com.interceptors;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class UserInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        ActionContext invocationContext = actionInvocation.getInvocationContext();

        Object user = invocationContext.getSession().get("user");
        if(user != null){
            return actionInvocation.invoke();
        }else {
            invocationContext.put("msg","您还没有登录，请先登录！");
            return Action.LOGIN;
        }
    }
}
